using System;
using System.IO;
using System.Text;
using SexpSharp.Remoting;
using SexpSharp.Serialization;

namespace SexpSharp.Serialization.Tests
{
	public class Test4
	{
		public void a() {
			serialize(new RemotableMethod<int, int>(i => i * i));
		}

		public static void Main(string[] argv)
		{
			Test4 t = new Test4();
			t.a();
		}

		static void deserialize(string expr)
		{
			MemoryStream s = new MemoryStream(new ASCIIEncoding().GetBytes(expr));
			object o = new SexpFormatter().Deserialize(s);
            Console.WriteLine(o);
		}

		static void serialize(object o)
		{
			SexpFormatter f = new SexpFormatter();
			f.SerializeFormat = Format.Advanced;
            MemoryStream s = new MemoryStream();
			f.Serialize(Console.OpenStandardError(), o);
			f.Serialize(s, o);
            Console.Error.WriteLine();
            s.Position = 0;
            object obj = f.Deserialize(s);
            Console.Error.WriteLine(obj);
            Console.Error.WriteLine(((Delegate) obj).DynamicInvoke(5));
		}
	}
}